<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php


require_once("global/classes/util/cls_ServiceLocator.php");
require_once("global/classes/util/cls_Locator.php");

ServiceLocator::attachLocator(new Locator('global/classes/util'), 'UTIL');
ServiceLocator::attachLocator(new Locator('main/classes/dao'), 'MAIN_DAO');
ServiceLocator::attachLocator(new Locator('global/classes/dao'), 'GLOBAL_DAO');
ServiceLocator::attachLocator(new Locator('main/classes/entity'), 'ENTITY');

/*
include_once "global/classes/dao/BaseDao.php";
include_once 'main/classes/dao/PaisDao.php';
include_once 'main/classes/dao/UFDao.php';
include_once 'main/classes/entity/Pais.php';
include_once 'main/classes/entity/UF.php';
*/
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo Constant::TITULO_SISTEMA?></title>
    </head>
    <body>
        Testando<br/>
        <?php
            $paisDao = new PaisDao();

            $paises = $paisDao->obterTodos();

            foreach ($paises as $pais) {
                echo $pais->getId()." - ".$pais->getNome()."<br/>";
            }

            echo "<h1>Inserindo novo pais</h1>";
            $paisTemp = new Pais();
            $paisTemp->setNome("pais".rand());
            $paisDao->inserir($paisTemp);

            echo "<h1>Inserindo nova UF</h1>";
            $paisTemp->setId($paisDao->lastId());
            $ufDao = new UFDao();

            $ufTemp = new UF();
            $ufTemp->setNome("Uf".rand());
            $ufTemp->setPais($paisTemp);
            $ufDao->inserir($ufTemp);


            echo "<h1>Rodando novamente</h1>";
            $paises = $paisDao->obterTodos();

            foreach ($paises as $pais) {
                echo "2 - ".$pais->getId()." - ".$pais->getNome()."<br/>";
            }


            $ufId = $ufDao->lastId();
            echo "<h1>Imprimindo a ultima UF - ".$ufId."</h1>";


            $ufTemp2 = $ufDao->get($ufId);
            echo $ufTemp2->getId()." - ".$ufTemp2->getNome()." - ". $ufTemp2->getPais()->getId()." - ". $ufTemp2->getPais()->getNome();


        ?>
    </body>
</html>
